package base.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

public class TestMain {
    public static void main(String[] args) {
        String resource = "mybatis/mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        try (SqlSession session = sqlSessionFactory.openSession()) {
            BlogMapper mapper = session.getMapper(BlogMapper.class);
            //Blog blog = mapper.selectBlog(1);
            Blog blog=new Blog();
            blog.setDatestr(new Date());
            blog.setTitle("aaa");
            //int count=mapper.insert(blog);
            System.out.println(222222);
            Blog blog2 = mapper.selectBlog(1);
            System.out.println(blog2);
            session.commit();
            session.close();
        }
    }
}
